package cn.itcast.mp.injectors;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 *  自定义MP SQL方法对象
 *  将该方法对象通过MP 的SQL注入器，注入到mappedStatements中
 */
public class FindAll  extends AbstractMethod {
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass,
                                                 Class<?> modelClass,
                                                 TableInfo tableInfo) {
        //仿照MP源码中AbstractMethod的实现类，所实现injectMappedStatement方法写
        //方法名
        String sqlMethod = "findAll";
        //SQL
        String sql = "select * from "  + tableInfo.getTableName();
        //生成sqlSource
        SqlSource sqlSource = languageDriver.createSqlSource(configuration,
                sql,
                modelClass);

        return this.addSelectMappedStatement(mapperClass,
                sqlMethod,
                sqlSource,
                modelClass,
                tableInfo);
    }
}
